from PySide6 import QtWidgets
from PySide6.QtWidgets import QWidget
from PySide6.QtCharts import QChart, QChartView, QLineSeries, QDateTimeAxis, QValueAxis
from PySide6.QtCore import Qt, QDateTime, QDate

class Demo(QWidget):
    """DateTime Axis Demo Class."""
    def __init__(self, parent=None):
        super().__init__(parent)
        
        # Create chart
        self.chart = QChart()
        self.chart.setTitle("DateTime Axis Example")
        
        # Create series
        series = QLineSeries()
        
        # Add data points with dates
        from PySide6.QtCore import QTime
        series.append(QDateTime(QDate(2025, 1, 1), QTime(0, 0, 0)).toMSecsSinceEpoch(), 3)
        series.append(QDateTime(QDate(2025, 2, 1), QTime(0, 0, 0)).toMSecsSinceEpoch(), 5)
        series.append(QDateTime(QDate(2025, 3, 1), QTime(0, 0, 0)).toMSecsSinceEpoch(), 2)
        series.append(QDateTime(QDate(2025, 4, 1), QTime(0, 0, 0)).toMSecsSinceEpoch(), 7)
        series.append(QDateTime(QDate(2025, 5, 1), QTime(0, 0, 0)).toMSecsSinceEpoch(), 4)
        
        self.chart.addSeries(series)
        
        # Create date time axis
        axisX = QDateTimeAxis()
        axisX.setFormat("MMM yyyy")
        axisX.setTitleText("Date")
        from PySide6.QtCore import QTime
        axisX.setRange(
            QDateTime(QDate(2025, 1, 1), QTime(0, 0, 0)),
            QDateTime(QDate(2025, 5, 1), QTime(0, 0, 0))
        )
        
        axisY = QValueAxis()
        axisY.setRange(0, 10)
        axisY.setTitleText("Value")
        
        self.chart.addAxis(axisX, Qt.AlignBottom)
        self.chart.addAxis(axisY, Qt.AlignLeft)
        
        series.attachAxis(axisX)
        series.attachAxis(axisY)
        
        # Create chart view
        chart_view = QChartView(self.chart)
        self.layout = QtWidgets.QVBoxLayout()
        self.layout.addWidget(chart_view)
        self.setLayout(self.layout)

def runDemo(parent):
    widget = Demo(parent)
    return widget